using HKB.Common;
using HKB.Data.Bll;
using HKB.Data.Model;
using System;
using System.Collections;
using System.Data;
using System.Web;
namespace HKB.Web.Shop
{
	public class CreateOrder
	{
		private Conn conn;
		public int OrderFormID;
		public string OrderFormNum;
		public int TradeType = 1;
		public int UserID = 0;
		public string BuyerName = "";
		public int ShopID = 0;
		public int SalerID = 0;
		public string SalerName = "";
		public decimal MoneyTotal = 0m;
		public decimal MoneyGoods = 0m;
		public decimal MoneyReceipt = 0m;
		public string Remark = "";
		public DateTime InputTime = DateTime.Now;
		public DateTime UpdateTime = DateTime.Now;
		public string Province = "";
		public string City = "";
		public string Area = "";
		public string Address = "";
		public string ZipCode = "";
		public string ContacterName = "";
		public string Mobile = "";
		public string Phone = "";
		public string Email = "";
		public int Status = 0;
		public int DeliverStatus = 0;
		public int PayStatus = 0;
		public string InvoiceType = "";
		public string InvoiceContent = "";
		public int Invoiced = 0;
		public int NeedInvoice = 0;
		public decimal Invoice_TotalPrice = 0m;
		public string DeliverTypeName = "";
		public decimal Deliver_TotalPrice = 0m;
		public int Cycle = 1;
		public decimal AuctionEndPrice = 0m;
		public int TeamBuyLeavel = 0;
		public decimal DeliverPrice = 0m;
		public decimal Increment = 0m;
		public string Color = "";
		public string Size = "";
		public string GuiGe = "";
		public int Invoid = 0;
		public bool isSingle = false;
		public int SelectedPayType = 0;
		public int CouponItemID = 0;
		public int PresentExpTotal = 0;
		public int NeedPresentExp = 0;
		public int DeliverTypeID = 0;
		public string DeliverCharge = "";
		public string ErrMsg;
		public CreateOrder()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public CreateOrder(Conn _conn)
		{
			this.conn = _conn;
		}
		public bool AddOrder(int[] ProductIDs, int[] ProductNum, int[] NeedInvoices, decimal newPrice)
		{
			if (string.IsNullOrEmpty(this.OrderFormNum))
			{
				this.OrderFormNum = DateTime.Now.ToString("yyyyMMddhhmmss") + Text.Random(6, 0);
			}
			string text = "";
			for (int i = 0; i < ProductIDs.Length; i++)
			{
				text = text + ProductIDs[i] + ",";
			}
			if (text != "")
			{
				text = text.Substring(0, text.Length - 1);
			}
			DataTable dataTable = this.conn.GetDataTable("Select ProductID,ProductName,ProductType,StandPrice,CurrentPrice,NeedInvoice,TaxRate,DeliverPayType,DeliverType,ColorAttribute,SizeAttribute,ShoppingCarGuige From [HLShop_Product] Where ProductID in(" + text + ")");
			for (int i = 0; i < NeedInvoices.Length; i++)
			{
				DataView defaultView = dataTable.DefaultView;
				defaultView.RowFilter = "ProductID=" + ProductIDs[i];
				if (this.MoneyGoods == 0m)
				{
					if (defaultView[0]["ProductType"].ToString() == "1")
					{
						this.MoneyGoods += newPrice * Convert.ToDecimal(ProductNum[i]);
					}
					else
					{
						this.MoneyGoods += Convert.ToDecimal(defaultView[0]["StandPrice"]) * Convert.ToDecimal(ProductNum[i]);
					}
				}
				if (this.Invoice_TotalPrice == 0m)
				{
					if (NeedInvoices[i] == 1)
					{
						if (defaultView[0]["NeedInvoice"].ToString() == "1" || defaultView[0]["NeedInvoice"].ToString() == "True")
						{
							this.NeedInvoice = 1;
							if (Text.ToDecimal(defaultView[0]["TaxRate"]) > 0m)
							{
								if (int.Parse(defaultView[0]["ProductType"].ToString()) == 3)
								{
									this.Invoice_TotalPrice += Text.ToDecimal(defaultView[0]["CurrentPrice"]) * Text.ToDecimal(defaultView[0]["TaxRate"]) / 100m;
								}
								else
								{
									if (int.Parse(defaultView[0]["ProductType"].ToString()) == 1)
									{
										this.Invoice_TotalPrice += newPrice * Text.ToDecimal(defaultView[0]["TaxRate"]) / 100m;
									}
									else
									{
										this.Invoice_TotalPrice += Text.ToDecimal(defaultView[0]["StandPrice"]) * Text.ToDecimal(defaultView[0]["TaxRate"]) / 100m;
									}
								}
							}
						}
					}
				}
				if (this.Deliver_TotalPrice == 0m)
				{
					for (int j = 0; j < ProductIDs.Length; j++)
					{
						DataView defaultView2 = dataTable.DefaultView;
						defaultView2.RowFilter = "ProductID = " + ProductIDs[j];
						this.Deliver_TotalPrice += this.DeliverPrice + (ProductNum[j] - 1) * this.Increment;
					}
				}
			}
			if (this.Invoice_TotalPrice > 0m)
			{
				this.Invoice_TotalPrice = decimal.Round(this.Invoice_TotalPrice, 2);
			}
			this.MoneyTotal = this.MoneyGoods + this.Invoice_TotalPrice + this.Deliver_TotalPrice;
			this.Invoiced = 0;
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
				this.conn.CreateParameter("@TradeType", DbType.Int32, this.TradeType),
				this.conn.CreateParameter("@UserID", DbType.Int32, this.UserID),
				this.conn.CreateParameter("@BuyerName", DbType.String, this.BuyerName),
				this.conn.CreateParameter("@ShopID", DbType.Int32, this.ShopID),
				this.conn.CreateParameter("@SalerID", DbType.Int32, this.SalerID),
				this.conn.CreateParameter("@SalerName", DbType.String, this.SalerName),
				this.conn.CreateParameter("@MoneyTotal", DbType.Decimal, this.MoneyTotal),
				this.conn.CreateParameter("@MoneyGoods", DbType.Decimal, this.MoneyGoods),
				this.conn.CreateParameter("@MoneyReceipt", DbType.Decimal, this.MoneyReceipt),
				this.conn.CreateParameter("@Remark", DbType.String, this.Remark),
				this.conn.CreateParameter("@InputTime", DbType.DateTime, this.InputTime),
				this.conn.CreateParameter("@UpdateTime", DbType.DateTime, this.UpdateTime),
				this.conn.CreateParameter("@Province", DbType.String, this.Province),
				this.conn.CreateParameter("@City", DbType.String, this.City),
				this.conn.CreateParameter("@Address", DbType.String, this.Address),
				this.conn.CreateParameter("@ZipCode", DbType.String, this.ZipCode),
				this.conn.CreateParameter("@ContacterName", DbType.String, this.ContacterName),
				this.conn.CreateParameter("@Mobile", DbType.String, this.Mobile),
				this.conn.CreateParameter("@Phone", DbType.String, this.Phone),
				this.conn.CreateParameter("@Email", DbType.String, this.Email),
				this.conn.CreateParameter("@Status", DbType.Int32, 0),
				this.conn.CreateParameter("@DeliverStatus", DbType.Int32, this.DeliverStatus),
				this.conn.CreateParameter("@PayStatus", DbType.Int32, this.PayStatus),
				this.conn.CreateParameter("@InvoiceContent", DbType.String, this.InvoiceContent),
				this.conn.CreateParameter("@Invoiced", DbType.Boolean, this.Invoiced),
				this.conn.CreateParameter("@NeedInvoice", DbType.Boolean, this.NeedInvoice),
				this.conn.CreateParameter("@Invoice_TotalPrice", DbType.Decimal, this.Invoice_TotalPrice),
				this.conn.CreateParameter("@DeliverTypeName", DbType.String, this.DeliverTypeName),
				this.conn.CreateParameter("@Deliver_TotalPrice", DbType.Decimal, this.Deliver_TotalPrice),
				this.conn.CreateParameter("@Cycle", DbType.Int32, this.Cycle),
				this.conn.CreateParameter("@AuctionEndPrice", DbType.Decimal, this.AuctionEndPrice),
				this.conn.CreateParameter("@TeamBuyLeavel", DbType.Int32, this.TeamBuyLeavel),
				this.conn.CreateParameter("@SelectedPayType", DbType.Int32, this.SelectedPayType),
				this.conn.CreateParameter("@InvoiceType", DbType.String, this.InvoiceType),
				this.conn.CreateParameter("@Color", DbType.String, this.Color),
				this.conn.CreateParameter("@Size", DbType.String, this.Size),
				this.conn.CreateParameter("@GuiGe", DbType.String, this.GuiGe)
			};
			string commandText = "INSERT INTO [HLShop_Order] (OrderFormNum,TradeType,UserID,BuyerName,ShopID,SalerID,SalerName,MoneyTotal,MoneyGoods,MoneyReceipt,Remark,InputTime,UpdateTime,Province,City,Address,ZipCode,ContacterName,Mobile,Phone,Email,Status,DeliverStatus,PayStatus,InvoiceContent,Invoiced,NeedInvoice,Invoice_TotalPrice,DeliverTypeName,Deliver_TotalPrice,Cycle,AuctionEndPrice,TeamBuyLeavel,SelectedPayType,InvoiceType,Color,Size,GuiGe) VALUES(@OrderFormNum,@TradeType,@UserID,@BuyerName,@ShopID,@SalerID,@SalerName,@MoneyTotal,@MoneyGoods,@MoneyReceipt,@Remark,@InputTime,@UpdateTime,@Province,@City,@Address,@ZipCode,@ContacterName,@Mobile,@Phone,@Email,@Status,@DeliverStatus,@PayStatus,@InvoiceContent,@Invoiced,@NeedInvoice,@Invoice_TotalPrice,@DeliverTypeName,@Deliver_TotalPrice,@Cycle,@AuctionEndPrice,@TeamBuyLeavel,@SelectedPayType,@InvoiceType,@Color,@Size,@GuiGe) select SCOPE_IDENTITY()";
			string commandText2 = "INSERT INTO [HLShop_OrderItem] (ProductID,ProductName,StandPrice,Price,InvoiceRate,OrderFormID,OrderFormNum,Quantity,NeedInvoice,totalPrice,Color,Size,GuiGe) VALUES (@ProductID,@ProductName,@StandPrice,@Price,@TaxRate,@OrderFormID,@OrderFormNum,@Quantity,@NeedInvoice,@totalPrice,@Color,@Size,@GuiGe)";
			this.conn.BeginTransaction();
			bool result;
			try
			{
				object value = this.conn.ExecuteTransactionScalar(commandText, parameters);
				this.OrderFormID = Convert.ToInt32(value);
				for (int i = 0; i < ProductIDs.Length; i++)
				{
					DataView defaultView = dataTable.DefaultView;
					defaultView.RowFilter = "ProductID=" + ProductIDs[i];
					decimal num;
					if (this.isSingle)
					{
						num = this.MoneyGoods / Convert.ToDecimal(ProductNum[0]);
					}
					else
					{
						if (defaultView[0]["ProductType"].ToString() == "1")
						{
							num = Text.ToDecimal(newPrice);
						}
						else
						{
							num = Text.ToDecimal(defaultView[0]["StandPrice"]);
						}
					}
					decimal num2 = num * ProductNum[i];
					num2 += this.Invoice_TotalPrice * ProductNum[0] + this.Deliver_TotalPrice;
					IDbDataParameter[] parameters2 = new IDbDataParameter[]
					{
						this.conn.CreateParameter("@ProductID", DbType.Int32, ProductIDs[i]),
						this.conn.CreateParameter("@ProductName", DbType.String, defaultView[0]["ProductName"].ToString()),
						this.conn.CreateParameter("@StandPrice", DbType.Decimal, Text.ToDecimal(defaultView[0]["StandPrice"])),
						this.conn.CreateParameter("@Price", DbType.Decimal, num),
						this.conn.CreateParameter("@TaxRate", DbType.Decimal, Text.ToDecimal(defaultView[0]["TaxRate"].ToString())),
						this.conn.CreateParameter("@OrderFormID", DbType.Int32, this.OrderFormID),
						this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
						this.conn.CreateParameter("@Quantity", DbType.Int32, ProductNum[i]),
						this.conn.CreateParameter("@NeedInvoice", DbType.Int32, NeedInvoices[i]),
						this.conn.CreateParameter("@totalPrice", DbType.Decimal, num2),
						this.conn.CreateParameter("@Color", DbType.String, this.Color),
						this.conn.CreateParameter("@Size", DbType.String, this.Size),
						this.conn.CreateParameter("@GuiGe", DbType.String, this.GuiGe)
					};
					this.conn.ExecuteTransaction(commandText2, parameters2);
				}
			}
			catch (Exception ex)
			{
				this.conn.Rollback();
				this.ErrMsg = ex.Message.ToString();
				result = false;
				return result;
			}
			this.conn.Commit();
			result = true;
			return result;
		}
		public bool creatOrders(DataTable needCreatDataTable)
		{
			decimal d = decimal.Parse("0.01");
			this.conn.BeginTransaction();
			foreach (DataRow dataRow in needCreatDataTable.Rows)
			{
				this.OrderFormNum = DateTime.Now.ToString("yyyyMMddhhmmss") + Text.Random(6, 0);
				this.TradeType = int.Parse(dataRow["TradeType"].ToString());
				this.UserID = int.Parse(dataRow["UserID"].ToString());
				this.BuyerName = dataRow["BuyerName"].ToString();
				this.ShopID = int.Parse(dataRow["shopID"].ToString());
				this.SalerID = int.Parse(dataRow["SalerID"].ToString());
				this.SalerName = dataRow["SalerName"].ToString();
				this.MoneyTotal = decimal.Parse(dataRow["MoneyTotal"].ToString());
				this.MoneyGoods = decimal.Parse(dataRow["MoneyGoods"].ToString());
				this.MoneyReceipt = 0m;
				this.Remark = dataRow["Remark"].ToString();
				this.Province = dataRow["Province"].ToString();
				this.City = dataRow["City"].ToString();
				this.Area = dataRow["Area"].ToString();
				this.Address = dataRow["Address"].ToString();
				this.ZipCode = dataRow["ZipCode"].ToString();
				this.ContacterName = dataRow["ContacterName"].ToString();
				this.Mobile = dataRow["Mobile"].ToString();
				this.Phone = dataRow["Phone"].ToString();
				this.Email = dataRow["Email"].ToString();
				this.InvoiceContent = dataRow["InvoiceContent"].ToString();
				this.Invoiced = 0;
				if (dataRow["InvoicedHas"].ToString() == "1")
				{
					this.Invoiced = Convert.ToInt32(dataRow["InvoicedHas"].ToString());
				}
				this.NeedInvoice = int.Parse(dataRow["NeedInvoice"].ToString());
				this.Invoice_TotalPrice = decimal.Parse(dataRow["Invoice_TotalPrice"].ToString());
				this.DeliverPrice = decimal.Parse(dataRow["DeliverPrice"].ToString());
				this.Increment = decimal.Parse(dataRow["Increment"].ToString());
				this.DeliverTypeName = dataRow["DeliverTypeName"].ToString();
				this.DeliverCharge = dataRow["deliverCharge"].ToString();
				this.Deliver_TotalPrice = decimal.Parse(dataRow["Deliver_TotalPrice"].ToString());
				this.CouponItemID = Convert.ToInt32(dataRow["CouponItemID"].ToString());
				this.DeliverTypeID = Convert.ToInt32(dataRow["DeliverTypeID"].ToString());
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
					this.conn.CreateParameter("@TradeType", DbType.Int32, this.TradeType),
					this.conn.CreateParameter("@UserID", DbType.Int32, this.UserID),
					this.conn.CreateParameter("@BuyerName", DbType.String, this.BuyerName),
					this.conn.CreateParameter("@ShopID", DbType.Int32, this.ShopID),
					this.conn.CreateParameter("@SalerID", DbType.Int32, this.SalerID),
					this.conn.CreateParameter("@SalerName", DbType.String, this.SalerName),
					this.conn.CreateParameter("@MoneyTotal", DbType.Decimal, this.MoneyTotal),
					this.conn.CreateParameter("@MoneyGoods", DbType.Decimal, this.MoneyGoods),
					this.conn.CreateParameter("@MoneyReceipt", DbType.Decimal, this.MoneyReceipt),
					this.conn.CreateParameter("@Remark", DbType.String, this.Remark),
					this.conn.CreateParameter("@InputTime", DbType.DateTime, this.InputTime),
					this.conn.CreateParameter("@UpdateTime", DbType.DateTime, this.UpdateTime),
					this.conn.CreateParameter("@Province", DbType.String, this.Province),
					this.conn.CreateParameter("@City", DbType.String, this.City),
					this.conn.CreateParameter("@Address", DbType.String, this.Address),
					this.conn.CreateParameter("@ZipCode", DbType.Int32, this.ZipCode),
					this.conn.CreateParameter("@ContacterName", DbType.String, this.ContacterName),
					this.conn.CreateParameter("@Mobile", DbType.String, this.Mobile),
					this.conn.CreateParameter("@Phone", DbType.String, this.Phone),
					this.conn.CreateParameter("@Email", DbType.String, this.Email),
					this.conn.CreateParameter("@Status", DbType.Int32, 0),
					this.conn.CreateParameter("@DeliverStatus", DbType.Int32, this.DeliverStatus),
					this.conn.CreateParameter("@PayStatus", DbType.Int32, this.PayStatus),
					this.conn.CreateParameter("@InvoiceContent", DbType.String, this.InvoiceContent),
					this.conn.CreateParameter("@Invoiced", DbType.Boolean, this.Invoiced),
					this.conn.CreateParameter("@NeedInvoice", DbType.Boolean, this.NeedInvoice),
					this.conn.CreateParameter("@Invoice_TotalPrice", DbType.Decimal, this.Invoice_TotalPrice),
					this.conn.CreateParameter("@DeliverTypeName", DbType.String, this.DeliverTypeName),
					this.conn.CreateParameter("@Deliver_TotalPrice", DbType.Decimal, this.Deliver_TotalPrice),
					this.conn.CreateParameter("@Cycle", DbType.Int32, this.Cycle),
					this.conn.CreateParameter("@AuctionEndPrice", DbType.Decimal, this.AuctionEndPrice),
					this.conn.CreateParameter("@TeamBuyLeavel", DbType.Int32, this.TeamBuyLeavel),
					this.conn.CreateParameter("@CouponItemID", DbType.Int32, this.CouponItemID),
					this.conn.CreateParameter("@DeliverTypeID", DbType.Int32, this.DeliverTypeID),
					this.conn.CreateParameter("@DeliverCharge", DbType.String, this.DeliverCharge),
					this.conn.CreateParameter("@Area", DbType.String, this.Area)
				};
				string commandText = "INSERT INTO [HLShop_Order] (OrderFormNum,TradeType,UserID,BuyerName,ShopID,SalerID,SalerName,MoneyTotal,MoneyGoods,MoneyReceipt,Remark,InputTime,UpdateTime,Province,City,Address,ZipCode,ContacterName,Mobile,Phone,Email,Status,DeliverStatus,PayStatus,InvoiceContent,Invoiced,NeedInvoice,Invoice_TotalPrice,DeliverTypeName,Deliver_TotalPrice,Cycle,AuctionEndPrice,TeamBuyLeavel,CouponItemID,DeliverTypeID,DeliverCharge,Area) VALUES(@OrderFormNum,@TradeType,@UserID,@BuyerName,@ShopID,@SalerID,@SalerName,@MoneyTotal,@MoneyGoods,@MoneyReceipt,@Remark,@InputTime,@UpdateTime,@Province,@City,@Address,@ZipCode,@ContacterName,@Mobile,@Phone,@Email,@Status,@DeliverStatus,@PayStatus,@InvoiceContent,@Invoiced,@NeedInvoice,@Invoice_TotalPrice,@DeliverTypeName,@Deliver_TotalPrice,@Cycle,@AuctionEndPrice,@TeamBuyLeavel,@CouponItemID,@DeliverTypeID,@DeliverCharge,@Area) select SCOPE_IDENTITY()";
				string commandText2 = "INSERT INTO [HLShop_OrderItem] (ProductID,ProductName,StandPrice,Price,InvoiceRate,OrderFormID,OrderFormNum,Quantity,NeedInvoice,totalPrice,ColorAttribute,SizeAttribute,GuiGe) VALUES (@ProductID,@ProductName,@StandPrice,@Price,@TaxRate,@OrderFormID,@OrderFormNum,@Quantity,@NeedInvoice,@totalPrice,@ColorAttribute,@SizeAttribute,@GuiGe)";
				string text = dataRow["orderProductIDS"].ToString();
				string[] array = text.Split(new char[]
				{
					','
				});
				string[] array2 = dataRow["productNum"].ToString().Split(new char[]
				{
					','
				});
				string[] array3 = dataRow["NeedInvoiceProduct"].ToString().Split(new char[]
				{
					','
				});
				string[] array4 = dataRow["StandPrice"].ToString().Split(new char[]
				{
					','
				});
				string sql = "SELECT ProductID,ProductName,StandPrice,NeedInvoice,TaxRate,DeliverPayType,DeliverType,PartPrice,ColorAttribute,SizeAttribute,ShoppingCarGuige FROM [HLShop_Product] WHERE ProductID in(" + text + ")";
				DataTable dataTableCommand = this.conn.getDataTableCommand(sql);
				object value = this.conn.ExecuteTransactionScalar(commandText, parameters);
				this.OrderFormID = Convert.ToInt32(value);
				for (int i = 0; i < array.Length; i++)
				{
					decimal d2 = 0m;
					DataView defaultView = dataTableCommand.DefaultView;
					defaultView.RowFilter = "ProductID=" + array[i];
					decimal num = Text.ToDecimal(array4[i]);
					decimal num2 = Text.ToDecimal(array4[i]);
					int value2 = int.Parse(array2[i]);
					decimal d3 = value2 * num;
					int num3 = int.Parse(array3[i]);
					this.NeedInvoice = num3;
					decimal num4 = Text.ToDecimal(defaultView[0]["TaxRate"]);
					if (num3 == 1)
					{
						if (num4 > 0m)
						{
							d2 = d3 * num4 * d;
						}
					}
					decimal d4 = 0m;
					if (this.DeliverTypeID > 0)
					{
						d4 = this.DeliverPrice + (int.Parse(array2[i]) - 1) * this.Increment;
					}
					decimal num5 = d3 + d2 + d4;
					IDbDataParameter[] parameters2 = new IDbDataParameter[]
					{
						this.conn.CreateParameter("@ProductID", DbType.Int32, array[i]),
						this.conn.CreateParameter("@Quantity", DbType.Int32, array2[i]),
						this.conn.CreateParameter("@NeedInvoice", DbType.Int32, this.NeedInvoice),
						this.conn.CreateParameter("@OrderFormID", DbType.Int32, this.OrderFormID),
						this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
						this.conn.CreateParameter("@ProductName", DbType.String, defaultView[0]["ProductName"].ToString()),
						this.conn.CreateParameter("@StandPrice", DbType.Decimal, num2),
						this.conn.CreateParameter("@Price", DbType.Decimal, num),
						this.conn.CreateParameter("@TaxRate", DbType.Decimal, num4),
						this.conn.CreateParameter("@totalPrice", DbType.Decimal, num5),
						this.conn.CreateParameter("@ColorAttribute", DbType.String, defaultView[0]["ColorAttribute"].ToString()),
						this.conn.CreateParameter("@SizeAttribute", DbType.String, defaultView[0]["SizeAttribute"].ToString()),
						this.conn.CreateParameter("@GuiGe", DbType.String, defaultView[0]["ShoppingCarGuige"].ToString())
					};
					this.conn.ExecuteTransaction(commandText2, parameters2);
					this.UserUseCoupon(this.CouponItemID);
				}
			}
			this.conn.Commit();
			return true;
		}
		public DataTable CreatOrderByDeliverType(string[] productIDS, string[] productNum, int userID)
		{
			DataTable dataTable = new DataTable();
			DataColumn column = new DataColumn("ShopID", typeof(int));
			dataTable.Columns.Add(column);
			DataColumn column2 = new DataColumn("ProductIDS", typeof(string));
			dataTable.Columns.Add(column2);
			DataColumn column3 = new DataColumn("ProductNum", typeof(string));
			dataTable.Columns.Add(column3);
			DataColumn column4 = new DataColumn("deliverType", typeof(int));
			dataTable.Columns.Add(column4);
			DataColumn column5 = new DataColumn("userID", typeof(int));
			dataTable.Columns.Add(column5);
			DataColumn column6 = new DataColumn("ShopName", typeof(string));
			dataTable.Columns.Add(column6);
			string text = "";
			for (int i = 0; i < productIDS.Length; i++)
			{
				text = text + productIDS[i] + ",";
			}
			text = text.Substring(0, text.Length - 1);
			Shop_Product shop_Product = new Shop_Product(this.conn);
			DataTable productadnshopByProductIDS = shop_Product.getProductadnshopByProductIDS(text);
			int[] array = new int[productadnshopByProductIDS.Rows.Count];
			for (int i = 0; i < productadnshopByProductIDS.Rows.Count; i++)
			{
				try
				{
					array[i] = int.Parse(productadnshopByProductIDS.Rows[i]["DeliverType"].ToString());
				}
				catch
				{
					array[i] = 0;
				}
			}
			ArrayList arrayList = new ArrayList();
			arrayList.Add(array[0]);
			for (int i = 1; i < array.Length; i++)
			{
				bool flag = true;
				for (int j = 0; j < arrayList.Count; j++)
				{
					if (array[i] == int.Parse(arrayList[j].ToString()))
					{
						flag = false;
					}
				}
				if (flag)
				{
					arrayList.Add(array[i]);
				}
			}
			string text2 = "";
			string text3 = "";
			int num = 0;
			int num2 = 0;
			string value = "";
			for (int i = 0; i < arrayList.Count; i++)
			{
				text2 = "";
				text3 = "";
				num = 0;
				num2 = 0;
				value = "";
				foreach (DataRow dataRow in productadnshopByProductIDS.Rows)
				{
					if (int.Parse(dataRow["deliverType"].ToString()) == int.Parse(arrayList[i].ToString()))
					{
						num = int.Parse(dataRow["ShopID"].ToString());
						value = dataRow["shopName"].ToString();
						text2 = text2 + dataRow["productID"].ToString() + ",";
						num2 = int.Parse(dataRow["deliverType"].ToString());
						for (int j = 0; j < productIDS.Length; j++)
						{
							if (dataRow["productID"].ToString() == productIDS[j])
							{
								text3 = text3 + productNum[j].ToString() + ",";
							}
						}
					}
				}
				DataRow dataRow2 = dataTable.NewRow();
				dataRow2["ShopID"] = num;
				dataRow2["productIDS"] = text2;
				dataRow2["productNum"] = text3;
				dataRow2["deliverType"] = num2;
				dataRow2["userID"] = userID;
				dataRow2["ShopName"] = value;
				dataTable.Rows.Add(dataRow2);
			}
			return dataTable;
		}
		public DataTable CreatOrderByDeliverType(string[] productIDS, string[] productNum, int userID, string[] productPrice)
		{
			DataTable dataTable = new DataTable();
			DataColumn column = new DataColumn("ShopID", typeof(int));
			dataTable.Columns.Add(column);
			DataColumn column2 = new DataColumn("ProductIDS", typeof(string));
			dataTable.Columns.Add(column2);
			DataColumn column3 = new DataColumn("ProductNum", typeof(string));
			dataTable.Columns.Add(column3);
			DataColumn column4 = new DataColumn("deliverType", typeof(int));
			dataTable.Columns.Add(column4);
			DataColumn column5 = new DataColumn("userID", typeof(int));
			dataTable.Columns.Add(column5);
			DataColumn column6 = new DataColumn("ShopName", typeof(string));
			dataTable.Columns.Add(column6);
			DataColumn column7 = new DataColumn("productPrice", typeof(string));
			dataTable.Columns.Add(column7);
			string text = "";
			for (int i = 0; i < productIDS.Length; i++)
			{
				text = text + productIDS[i] + ",";
			}
			text = text.Substring(0, text.Length - 1);
			Shop_Product shop_Product = new Shop_Product(this.conn);
			DataTable productadnshopByProductIDS = shop_Product.getProductadnshopByProductIDS(text);
			string text2 = "";
			string text3 = "";
			for (int i = 0; i < productadnshopByProductIDS.Rows.Count; i++)
			{
				int num = productadnshopByProductIDS.Rows[i]["SalerID"].ToString().ToInt32(new int[0]);
				if (num > 0)
				{
					int num2 = 0;
					try
					{
						if (productadnshopByProductIDS.Rows[i]["DeliverPayType"] != DBNull.Value)
						{
							if (productadnshopByProductIDS.Rows[i]["DeliverPayType"].ToString().Trim() == "1")
							{
								if (productadnshopByProductIDS.Rows[i]["DeliverType"] != DBNull.Value)
								{
									num2 = productadnshopByProductIDS.Rows[i]["DeliverType"].ToString().ToInt32(new int[0]);
								}
							}
							else
							{
								num2 = 0;
							}
						}
					}
					catch
					{
						num2 = 0;
					}
					object obj = text3;
					text3 = string.Concat(new object[]
					{
						obj,
						num,
						",",
						num2,
						"|"
					});
					text2 = text2 + num + "|";
				}
			}
			Hashtable hashtable = new Hashtable();
			if (!string.IsNullOrEmpty(text3))
			{
				text3 = text3.Substring(0, text3.Length - 1);
				text2 = text2.Substring(0, text2.Length - 1);
				ArrayList arrayList = new ArrayList();
				string[] array = text2.Split(new char[]
				{
					'|'
				});
				for (int j = 0; j < array.Length; j++)
				{
					string text4 = array[j].ToString();
					if (!arrayList.Contains(text4))
					{
						arrayList.Add(text4);
					}
				}
				for (int k = 0; k < arrayList.Count; k++)
				{
					string text5 = arrayList[k].ToString();
					string key = text5;
					string text6 = "";
					string[] array2 = text3.Split(new char[]
					{
						'|'
					});
					for (int l = 0; l < array2.Length; l++)
					{
						string[] array3 = array2[l].Split(new char[]
						{
							','
						});
						if (array3.Length >= 2)
						{
							if (text5 == array3[0].Trim())
							{
								text6 = text6 + array3[1] + ",";
							}
						}
					}
					if (!string.IsNullOrEmpty(text6))
					{
						text6 = text6.Substring(0, text6.Length - 1);
						hashtable.Add(key, text6);
					}
				}
			}
			ArrayList arrayList2 = new ArrayList(hashtable.Keys);
			foreach (string text7 in arrayList2)
			{
				string[] array4 = hashtable[text7].ToString().Split(new char[]
				{
					','
				});
				if (array4.Length > 0)
				{
					int[] array5 = new int[array4.Length];
					for (int m = 0; m < array4.Length; m++)
					{
						array5[m] = array4[m].ToInt32(new int[0]);
					}
					ArrayList arrayList3 = new ArrayList();
					arrayList3.Add(array5[0]);
					for (int i = 1; i < array5.Length; i++)
					{
						bool flag = true;
						for (int n = 0; n < arrayList3.Count; n++)
						{
							if (array5[i] == int.Parse(arrayList3[n].ToString()))
							{
								flag = false;
							}
						}
						if (flag)
						{
							arrayList3.Add(array5[i]);
						}
					}
					DataView defaultView = productadnshopByProductIDS.DefaultView;
					defaultView.RowFilter = "SalerID=" + int.Parse(text7);
					string text8 = "";
					string text9 = "";
					string text10 = "";
					int num3 = 0;
					int num4 = 0;
					string value = "";
					for (int i = 0; i < arrayList3.Count; i++)
					{
						text8 = "";
						text9 = "";
						text10 = "";
						num3 = 0;
						num4 = 0;
						value = "";
						foreach (DataRowView dataRowView in defaultView)
						{
							if (int.Parse(dataRowView["deliverType"].ToString()) == int.Parse(arrayList3[i].ToString()))
							{
								num3 = int.Parse(dataRowView["ShopID"].ToString());
								value = dataRowView["shopName"].ToString();
								text8 = text8 + dataRowView["productID"].ToString() + ",";
								num4 = int.Parse(dataRowView["deliverType"].ToString());
								for (int n = 0; n < productIDS.Length; n++)
								{
									if (dataRowView["productID"].ToString() == productIDS[n])
									{
										text9 = text9 + productNum[n].ToString() + ",";
										text10 = text10 + productPrice[n].ToString() + ",";
										break;
									}
								}
							}
						}
						if (!string.IsNullOrEmpty(text8))
						{
							DataRow dataRow = dataTable.NewRow();
							dataRow["ShopID"] = num3;
							dataRow["productIDS"] = text8;
							dataRow["productNum"] = text9;
							dataRow["deliverType"] = num4;
							dataRow["userID"] = userID;
							dataRow["ShopName"] = value;
							dataRow["productPrice"] = text10;
							dataTable.Rows.Add(dataRow);
						}
					}
				}
			}
			return dataTable;
		}
		public bool AddOrder(int ProductID, int ProductNum, int NeedInvoice, decimal newPrice)
		{
			return this.AddOrder(new int[]
			{
				ProductID
			}, new int[]
			{
				ProductNum
			}, new int[]
			{
				NeedInvoice
			}, newPrice);
		}
		public decimal GetDeliverPrice(int[] productNum, decimal deliverPrice, decimal increment)
		{
			int num = 0;
			for (int i = 0; i < productNum.Length; i++)
			{
				num += productNum[i];
			}
			return deliverPrice + (num - 1) * increment;
		}
		public decimal GetProductTotalPrice(int[] productID, int[] productNum)
		{
			decimal num = 0m;
			for (int i = 0; i < productID.Length; i++)
			{
				DataTable dataTable = this.conn.GetDataTable(string.Format("SELECT StandPrice FROM HLShop_Product WHERE ProductID={0}", productID[i]));
				num += decimal.Parse(dataTable.Rows[0]["StandPrice"].ToString()) * productNum[i];
			}
			return num;
		}
		public decimal GetProductTotalPrice(int[] productID, int[] productNum, decimal[] productPrice)
		{
			decimal num = 0m;
			for (int i = 0; i < productID.Length; i++)
			{
				num += productPrice[i] * productNum[i];
			}
			return num;
		}
		public bool UserOneSecondsKill(int UserID, int ProductID)
		{
			string commandText = string.Concat(new object[]
			{
				"SELECT Count(*) FROM HLShop_Order,HLShop_OrderItem WHERE HLShop_Order.OrderFormID = HLShop_OrderItem.OrderFormID AND UserID =",
				UserID,
				" AND ProductID= ",
				ProductID
			});
			return (int)this.conn.GetScalar(commandText, new IDbDataParameter[0]) == 1;
		}
		public bool AddOrder(int ProductID, int ProductNum, int NeedInvoice, decimal newPrice, decimal defaultPrice, decimal defIncrement, int couponItemId)
		{
			if (string.IsNullOrEmpty(this.OrderFormNum))
			{
				this.OrderFormNum = DateTime.Now.ToString("yyyyMMddhhmmss") + Text.Random(6, 0);
			}
			DataTable dataTable = this.conn.GetDataTable("Select ProductID,ProductName,ProductType,StandPrice,CurrentPrice,NeedInvoice,TaxRate,DeliverPayType,DeliverType,ColorAttribute,SizeAttribute,ShoppingCarGuige,NeedPresentExp From [HLShop_Product] Where ProductID in(" + ProductID + ")");
			bool result;
			if (dataTable.Rows.Count > 0)
			{
				this.MoneyGoods = 0m;
				this.Invoice_TotalPrice = 0m;
				this.Deliver_TotalPrice = 0m;
				DataView defaultView = dataTable.DefaultView;
				defaultView.RowFilter = "ProductID=" + ProductID;
				string a = defaultView[0]["ProductType"].ToString();
				decimal num = 0m;
				decimal num2 = 0m;
				if (a == "1")
				{
					num = newPrice;
					num2 = newPrice;
				}
				else
				{
					if (a == "3")
					{
						num = newPrice;
						num2 = newPrice;
						if (defaultView[0]["StandPrice"] != DBNull.Value)
						{
							num2 = Text.ToDecimal(defaultView[0]["StandPrice"].ToString());
						}
					}
					else
					{
						if (a == "4")
						{
							num = newPrice;
							num2 = newPrice;
							if (defaultView[0]["CurrentPrice"] != DBNull.Value)
							{
								num2 = Text.ToDecimal(defaultView[0]["CurrentPrice"].ToString());
							}
						}
						else
						{
							if (a == "5")
							{
								num2 = newPrice;
								num = 0m;
								if (defaultView[0]["NeedPresentExp"] != DBNull.Value)
								{
									this.NeedPresentExp = Convert.ToInt32(defaultView[0]["NeedPresentExp"].ToString());
									this.PresentExpTotal = this.NeedPresentExp * ProductNum;
								}
							}
						}
					}
				}
				this.MoneyGoods += num * ProductNum;
				string a2 = defaultView[0]["NeedInvoice"].ToString();
				decimal num3 = Text.ToDecimal(defaultView[0]["TaxRate"]);
				if (a2 == "1" || a2 == "True")
				{
					NeedInvoice = 1;
					this.Invoice_TotalPrice += this.CalculateInvoiceMoney(newPrice, ProductNum, num3, NeedInvoice);
				}
				this.DeliverPrice = defaultPrice;
				this.Increment = defIncrement;
				this.Deliver_TotalPrice += this.DeliverPrice + (ProductNum - 1) * this.Increment;
				this.CouponItemID = couponItemId;
				decimal couponValue = BLLInstance.BllCouponItem.GetCouponValue(couponItemId);
				if (this.Invoice_TotalPrice > 0m)
				{
					this.Invoice_TotalPrice = decimal.Round(this.Invoice_TotalPrice, 2);
				}
				this.MoneyTotal = this.MoneyGoods + this.Invoice_TotalPrice + this.Deliver_TotalPrice - couponValue;
				if (this.MoneyTotal == 0m)
				{
					this.PayStatus = 1;
				}
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
					this.conn.CreateParameter("@TradeType", DbType.Int32, this.TradeType),
					this.conn.CreateParameter("@UserID", DbType.Int32, this.UserID),
					this.conn.CreateParameter("@BuyerName", DbType.String, this.BuyerName),
					this.conn.CreateParameter("@ShopID", DbType.Int32, this.ShopID),
					this.conn.CreateParameter("@SalerID", DbType.Int32, this.SalerID),
					this.conn.CreateParameter("@SalerName", DbType.String, this.SalerName),
					this.conn.CreateParameter("@MoneyTotal", DbType.Decimal, this.MoneyTotal),
					this.conn.CreateParameter("@MoneyGoods", DbType.Decimal, this.MoneyGoods),
					this.conn.CreateParameter("@MoneyReceipt", DbType.Decimal, this.MoneyReceipt),
					this.conn.CreateParameter("@Remark", DbType.String, this.Remark),
					this.conn.CreateParameter("@InputTime", DbType.DateTime, this.InputTime),
					this.conn.CreateParameter("@UpdateTime", DbType.DateTime, this.UpdateTime),
					this.conn.CreateParameter("@Province", DbType.String, this.Province),
					this.conn.CreateParameter("@City", DbType.String, this.City),
					this.conn.CreateParameter("@Address", DbType.String, this.Address),
					this.conn.CreateParameter("@ZipCode", DbType.String, this.ZipCode),
					this.conn.CreateParameter("@ContacterName", DbType.String, this.ContacterName),
					this.conn.CreateParameter("@Mobile", DbType.String, this.Mobile),
					this.conn.CreateParameter("@Phone", DbType.String, this.Phone),
					this.conn.CreateParameter("@Email", DbType.String, this.Email),
					this.conn.CreateParameter("@Status", DbType.Int32, 0),
					this.conn.CreateParameter("@DeliverStatus", DbType.Int32, this.DeliverStatus),
					this.conn.CreateParameter("@PayStatus", DbType.Int32, this.PayStatus),
					this.conn.CreateParameter("@InvoiceContent", DbType.String, this.InvoiceContent),
					this.conn.CreateParameter("@Invoiced", DbType.Boolean, this.Invoiced),
					this.conn.CreateParameter("@NeedInvoice", DbType.Boolean, NeedInvoice),
					this.conn.CreateParameter("@Invoice_TotalPrice", DbType.Decimal, this.Invoice_TotalPrice),
					this.conn.CreateParameter("@DeliverTypeName", DbType.String, this.DeliverTypeName),
					this.conn.CreateParameter("@Deliver_TotalPrice", DbType.Decimal, this.Deliver_TotalPrice),
					this.conn.CreateParameter("@Cycle", DbType.Int32, this.Cycle),
					this.conn.CreateParameter("@AuctionEndPrice", DbType.Decimal, this.AuctionEndPrice),
					this.conn.CreateParameter("@TeamBuyLeavel", DbType.Int32, this.TeamBuyLeavel),
					this.conn.CreateParameter("@SelectedPayType", DbType.Int32, this.SelectedPayType),
					this.conn.CreateParameter("@InvoiceType", DbType.String, this.InvoiceType),
					this.conn.CreateParameter("@Color", DbType.String, this.Color),
					this.conn.CreateParameter("@Size", DbType.String, this.Size),
					this.conn.CreateParameter("@GuiGe", DbType.String, this.GuiGe),
					this.conn.CreateParameter("@CouponItemID", DbType.Int32, this.CouponItemID),
					this.conn.CreateParameter("@PresentExpTotal", DbType.Int32, this.PresentExpTotal),
					this.conn.CreateParameter("@DeliverTypeID", DbType.Int32, this.DeliverTypeID),
					this.conn.CreateParameter("@DeliverCharge", DbType.String, this.DeliverCharge),
					this.conn.CreateParameter("@Area", DbType.String, this.Area)
				};
				string commandText = "INSERT INTO [HLShop_Order] (OrderFormNum,TradeType,UserID,BuyerName,ShopID,SalerID,SalerName,MoneyTotal,MoneyGoods,MoneyReceipt,Remark,InputTime,UpdateTime,Province,City,Address,ZipCode,ContacterName,Mobile,Phone,Email,Status,DeliverStatus,PayStatus,InvoiceContent,Invoiced,NeedInvoice,Invoice_TotalPrice,DeliverTypeName,Deliver_TotalPrice,Cycle,AuctionEndPrice,TeamBuyLeavel,SelectedPayType,InvoiceType,Color,Size,GuiGe,CouponItemID,PresentExpTotal,DeliverTypeID,DeliverCharge,Area) VALUES(@OrderFormNum,@TradeType,@UserID,@BuyerName,@ShopID,@SalerID,@SalerName,@MoneyTotal,@MoneyGoods,@MoneyReceipt,@Remark,@InputTime,@UpdateTime,@Province,@City,@Address,@ZipCode,@ContacterName,@Mobile,@Phone,@Email,@Status,@DeliverStatus,@PayStatus,@InvoiceContent,@Invoiced,@NeedInvoice,@Invoice_TotalPrice,@DeliverTypeName,@Deliver_TotalPrice,@Cycle,@AuctionEndPrice,@TeamBuyLeavel,@SelectedPayType,@InvoiceType,@Color,@Size,@GuiGe,@CouponItemID,@PresentExpTotal,@DeliverTypeID,@DeliverCharge,@Area) select SCOPE_IDENTITY()";
				string commandText2 = "INSERT INTO [HLShop_OrderItem] (ProductID,ProductName,StandPrice,Price,InvoiceRate,OrderFormID,OrderFormNum,Quantity,NeedInvoice,totalPrice,Color,Size,GuiGe,NeedPresentExp) VALUES (@ProductID,@ProductName,@StandPrice,@Price,@TaxRate,@OrderFormID,@OrderFormNum,@Quantity,@NeedInvoice,@totalPrice,@Color,@Size,@GuiGe,@NeedPresentExp)";
				this.conn.BeginTransaction();
				try
				{
					object value = this.conn.ExecuteTransactionScalar(commandText, parameters);
					this.OrderFormID = Convert.ToInt32(value);
					IDbDataParameter[] parameters2 = new IDbDataParameter[]
					{
						this.conn.CreateParameter("@ProductID", DbType.Int32, ProductID),
						this.conn.CreateParameter("@ProductName", DbType.String, defaultView[0]["ProductName"].ToString()),
						this.conn.CreateParameter("@StandPrice", DbType.Decimal, num2),
						this.conn.CreateParameter("@Price", DbType.Decimal, num),
						this.conn.CreateParameter("@TaxRate", DbType.Decimal, num3),
						this.conn.CreateParameter("@OrderFormID", DbType.Int32, this.OrderFormID),
						this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
						this.conn.CreateParameter("@Quantity", DbType.Int32, ProductNum),
						this.conn.CreateParameter("@NeedInvoice", DbType.Int32, NeedInvoice),
						this.conn.CreateParameter("@totalPrice", DbType.Decimal, this.MoneyTotal),
						this.conn.CreateParameter("@Color", DbType.String, this.Color),
						this.conn.CreateParameter("@Size", DbType.String, this.Size),
						this.conn.CreateParameter("@GuiGe", DbType.String, this.GuiGe),
						this.conn.CreateParameter("@NeedPresentExp", DbType.Int32, this.NeedPresentExp)
					};
					this.conn.ExecuteTransaction(commandText2, parameters2);
					this.UserUseCoupon(this.CouponItemID);
				}
				catch (Exception ex)
				{
					this.conn.Rollback();
					this.ErrMsg = ex.Message.ToString();
					result = false;
					return result;
				}
				this.conn.Commit();
			}
			result = true;
			return result;
		}
		private string ItemStr(string[] productStrChild, string NeedInvioceStr)
		{
			string text = "";
			if (productStrChild.Length >= 4)
			{
				string text2 = "";
				int num = Convert.ToInt32(productStrChild[0]);
				int num2 = Convert.ToInt32(productStrChild[1]);
				decimal num3 = Convert.ToDecimal(productStrChild[2]);
				int num4 = 0;
				string invoiceContent = "";
				if (!string.IsNullOrEmpty(NeedInvioceStr))
				{
					this.Invoiced = 1;
					if (NeedInvioceStr.Contains("|"))
					{
						string[] array = NeedInvioceStr.Split(new char[]
						{
							'|'
						});
						for (int i = 0; i < array.Length; i++)
						{
							string[] array2 = array[i].Split(new char[]
							{
								','
							});
							if (array2.Length >= 3)
							{
								if (num == Convert.ToInt32(array2[0]))
								{
									num4 = Convert.ToInt32(array2[1]);
									invoiceContent = array2[2];
								}
							}
						}
					}
					else
					{
						string[] array3 = NeedInvioceStr.Split(new char[]
						{
							','
						});
						if (array3.Length >= 3)
						{
							if (num == Convert.ToInt32(array3[0]))
							{
								num4 = Convert.ToInt32(array3[1]);
								invoiceContent = array3[2];
							}
						}
					}
					this.NeedInvoice = num4;
					this.InvoiceContent = invoiceContent;
				}
				DataTable dataTable = this.conn.GetDataTable("Select ProductID,ProductName,ProductType,StandPrice,CurrentPrice,NeedInvoice,TaxRate,DeliverPayType,DeliverType,ColorAttribute,SizeAttribute,ShoppingCarGuige,Color,Size,NeedPresentExp From [HLShop_Product] Where ProductID in(" + num + ")");
				if (dataTable.Rows.Count > 0)
				{
					DataRow dataRow = dataTable.Rows[0];
					string a = dataRow["ProductType"].ToString();
					decimal num5 = 0m;
					decimal num6 = 0m;
					if (a == "1")
					{
						num6 = num3 * num2;
						num5 = Convert.ToDecimal(dataRow["StandPrice"].ToString());
					}
					else
					{
						if (a == "4")
						{
							num6 = num3 * num2;
							num5 = Convert.ToDecimal(dataRow["CurrentPrice"].ToString());
						}
						else
						{
							if (a == "5")
							{
								num5 = Convert.ToDecimal(dataRow["StandPrice"].ToString());
								if (dataRow["NeedPresentExp"] != DBNull.Value)
								{
									this.NeedPresentExp = Convert.ToInt32(dataRow["NeedPresentExp"].ToString());
									this.PresentExpTotal = this.NeedPresentExp * num2;
								}
							}
						}
					}
					this.MoneyGoods += num6;
					decimal d = 0m;
					decimal num7 = 0m;
					if (num4 == 1)
					{
						decimal d2 = num3 * num2;
						if (dataRow["NeedInvoice"].ToString() == "1" || dataRow["NeedInvoice"].ToString().ToLower().Trim() == "true")
						{
							num7 = Convert.ToDecimal(dataRow["TaxRate"].ToString());
							if (num7 > 0m)
							{
								d = d2 * num7 / 100m;
							}
						}
					}
					this.Invoice_TotalPrice += d;
					decimal num8 = 0m;
					this.DeliverTypeID = Convert.ToInt32(dataRow["DeliverType"].ToString());
					if (dataRow["DeliverPayType"].ToString() != "0")
					{
						Shop_DeliverType shop_DeliverType = new Shop_DeliverType(this.conn);
						if (!string.IsNullOrEmpty(this.DeliverCharge))
						{
							string[] contentArray = this.DeliverCharge.ToString().Split(new char[]
							{
								'$'
							});
							string deliverChargeContentDetailByName = Shop_DeliverType.GetDeliverChargeContentDetailByName("deliverTypeID", contentArray);
							if (!string.IsNullOrEmpty(deliverChargeContentDetailByName))
							{
								this.DeliverTypeID = Convert.ToInt32(deliverChargeContentDetailByName);
							}
							this.DeliverTypeName = Shop_DeliverType.GetDeliverChargeContentDetailByName("deliverName", contentArray);
							decimal d3 = 0m;
							decimal d4 = 0m;
							string deliverChargeContentDetailByName2 = Shop_DeliverType.GetDeliverChargeContentDetailByName("defaultPrice", contentArray);
							if (!string.IsNullOrEmpty(deliverChargeContentDetailByName2))
							{
								d3 = deliverChargeContentDetailByName2.ToDecimal2();
							}
							string deliverChargeContentDetailByName3 = Shop_DeliverType.GetDeliverChargeContentDetailByName("deincrementPrice", contentArray);
							if (!string.IsNullOrEmpty(deliverChargeContentDetailByName3))
							{
								d4 = deliverChargeContentDetailByName3.ToDecimal2();
							}
							num8 += d3 + (num2 - 1) * d4;
						}
					}
					this.Deliver_TotalPrice += num8;
					decimal num9 = num6 + d + num8;
					this.MoneyTotal += num9;
					string text3 = dataRow["ProductName"].ToString();
					string text4 = dataRow["Color"].ToString();
					string text5 = dataRow["Size"].ToString();
					string text6 = dataRow["ShoppingCarGuige"].ToString();
					text2 = string.Concat(new object[]
					{
						num,
						",",
						text3,
						",",
						num2,
						",",
						num5,
						",",
						num3,
						",",
						num4,
						",",
						num7,
						",",
						num9,
						",",
						this.NeedPresentExp,
						",",
						text4,
						",",
						text5,
						",",
						text6,
						"|"
					});
				}
				if (text2 != "")
				{
					text += text2;
				}
			}
			return text;
		}
		private IDbDataParameter[] OrderItemParameter(string[] oiStrChild)
		{
			IDbDataParameter[] result = null;
			if (oiStrChild.Length >= 12)
			{
				int num = Convert.ToInt32(oiStrChild[0]);
				string value = oiStrChild[1];
				int num2 = Convert.ToInt32(oiStrChild[2]);
				decimal num3 = Convert.ToDecimal(oiStrChild[3]);
				decimal num4 = Convert.ToDecimal(oiStrChild[4]);
				int num5 = Convert.ToInt32(oiStrChild[5]);
				decimal num6 = Convert.ToDecimal(oiStrChild[6]);
				decimal num7 = Convert.ToDecimal(oiStrChild[7]);
				int num8 = Convert.ToInt32(oiStrChild[8]);
				string value2 = oiStrChild[9];
				string value3 = oiStrChild[10];
				string value4 = oiStrChild[11];
				result = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@ProductID", DbType.Int32, num),
					this.conn.CreateParameter("@ProductName", DbType.String, value),
					this.conn.CreateParameter("@StandPrice", DbType.Decimal, num3),
					this.conn.CreateParameter("@Price", DbType.Decimal, num4),
					this.conn.CreateParameter("@TaxRate", DbType.Decimal, num6),
					this.conn.CreateParameter("@OrderFormID", DbType.Int32, this.OrderFormID),
					this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
					this.conn.CreateParameter("@Quantity", DbType.Int32, num2),
					this.conn.CreateParameter("@NeedInvoice", DbType.Int32, num5),
					this.conn.CreateParameter("@totalPrice", DbType.Decimal, num7),
					this.conn.CreateParameter("@Color", DbType.String, value2),
					this.conn.CreateParameter("@Size", DbType.String, value3),
					this.conn.CreateParameter("@GuiGe", DbType.String, value4),
					this.conn.CreateParameter("@NeedPresentExp", DbType.Int32, num8)
				};
			}
			return result;
		}
		public int OrderAddHand(string ProductStr, string NeedInvioceStr)
		{
			int result = 0;
			string text = "";
			if (!string.IsNullOrEmpty(ProductStr))
			{
				if (ProductStr.Contains("|"))
				{
					string[] array = ProductStr.Split(new char[]
					{
						'|'
					});
					for (int i = 0; i < array.Length; i++)
					{
						string[] productStrChild = array[i].Split(new char[]
						{
							','
						});
						text += this.ItemStr(productStrChild, NeedInvioceStr);
					}
				}
				else
				{
					string[] productStrChild2 = ProductStr.Split(new char[]
					{
						','
					});
					text += this.ItemStr(productStrChild2, NeedInvioceStr);
				}
				string commandText = "INSERT INTO [HLShop_Order] (OrderFormNum,TradeType,UserID,BuyerName,ShopID,SalerID,SalerName,MoneyTotal,MoneyGoods,MoneyReceipt,Remark,InputTime,UpdateTime,Province,City,Address,ZipCode,ContacterName,Mobile,Phone,Email,Status,DeliverStatus,PayStatus,InvoiceContent,Invoiced,NeedInvoice,Invoice_TotalPrice,DeliverTypeName,Deliver_TotalPrice,Cycle,AuctionEndPrice,TeamBuyLeavel,SelectedPayType,InvoiceType,Color,Size,GuiGe,CouponItemID,PresentExpTotal,DeliverTypeID,DeliverCharge) VALUES(@OrderFormNum,@TradeType,@UserID,@BuyerName,@ShopID,@SalerID,@SalerName,@MoneyTotal,@MoneyGoods,@MoneyReceipt,@Remark,@InputTime,@UpdateTime,@Province,@City,@Address,@ZipCode,@ContacterName,@Mobile,@Phone,@Email,@Status,@DeliverStatus,@PayStatus,@InvoiceContent,@Invoiced,@NeedInvoice,@Invoice_TotalPrice,@DeliverTypeName,@Deliver_TotalPrice,@Cycle,@AuctionEndPrice,@TeamBuyLeavel,@SelectedPayType,@InvoiceType,@Color,@Size,@GuiGe,@CouponItemID,@PresentExpTotal,@DeliverTypeID,@DeliverCharge) select SCOPE_IDENTITY()";
				string commandText2 = "INSERT INTO [HLShop_OrderItem] (ProductID,ProductName,StandPrice,Price,InvoiceRate,OrderFormID,OrderFormNum,Quantity,NeedInvoice,totalPrice,Color,Size,GuiGe,NeedPresentExp) VALUES (@ProductID,@ProductName,@StandPrice,@Price,@TaxRate,@OrderFormID,@OrderFormNum,@Quantity,@NeedInvoice,@totalPrice,@Color,@Size,@GuiGe,@NeedPresentExp)";
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@OrderFormNum", DbType.String, this.OrderFormNum),
					this.conn.CreateParameter("@TradeType", DbType.Int32, this.TradeType),
					this.conn.CreateParameter("@UserID", DbType.Int32, this.UserID),
					this.conn.CreateParameter("@BuyerName", DbType.String, this.BuyerName),
					this.conn.CreateParameter("@ShopID", DbType.Int32, this.ShopID),
					this.conn.CreateParameter("@SalerID", DbType.Int32, this.SalerID),
					this.conn.CreateParameter("@SalerName", DbType.String, this.SalerName),
					this.conn.CreateParameter("@MoneyTotal", DbType.Decimal, this.MoneyTotal),
					this.conn.CreateParameter("@MoneyGoods", DbType.Decimal, this.MoneyGoods),
					this.conn.CreateParameter("@MoneyReceipt", DbType.Decimal, this.MoneyReceipt),
					this.conn.CreateParameter("@Remark", DbType.String, this.Remark),
					this.conn.CreateParameter("@InputTime", DbType.DateTime, this.InputTime),
					this.conn.CreateParameter("@UpdateTime", DbType.DateTime, this.UpdateTime),
					this.conn.CreateParameter("@Province", DbType.String, this.Province),
					this.conn.CreateParameter("@City", DbType.String, this.City),
					this.conn.CreateParameter("@Address", DbType.String, this.Address),
					this.conn.CreateParameter("@ZipCode", DbType.String, this.ZipCode),
					this.conn.CreateParameter("@ContacterName", DbType.String, this.ContacterName),
					this.conn.CreateParameter("@Mobile", DbType.String, this.Mobile),
					this.conn.CreateParameter("@Phone", DbType.String, this.Phone),
					this.conn.CreateParameter("@Email", DbType.String, this.Email),
					this.conn.CreateParameter("@Status", DbType.Int32, this.Status),
					this.conn.CreateParameter("@DeliverStatus", DbType.Int32, this.DeliverStatus),
					this.conn.CreateParameter("@PayStatus", DbType.Int32, this.PayStatus),
					this.conn.CreateParameter("@InvoiceContent", DbType.String, this.InvoiceContent),
					this.conn.CreateParameter("@Invoiced", DbType.Boolean, this.Invoiced),
					this.conn.CreateParameter("@NeedInvoice", DbType.Boolean, this.NeedInvoice),
					this.conn.CreateParameter("@Invoice_TotalPrice", DbType.Decimal, this.Invoice_TotalPrice),
					this.conn.CreateParameter("@DeliverTypeName", DbType.String, this.DeliverTypeName),
					this.conn.CreateParameter("@Deliver_TotalPrice", DbType.Decimal, this.Deliver_TotalPrice),
					this.conn.CreateParameter("@Cycle", DbType.Int32, this.Cycle),
					this.conn.CreateParameter("@AuctionEndPrice", DbType.Decimal, this.AuctionEndPrice),
					this.conn.CreateParameter("@TeamBuyLeavel", DbType.Int32, this.TeamBuyLeavel),
					this.conn.CreateParameter("@SelectedPayType", DbType.Int32, this.SelectedPayType),
					this.conn.CreateParameter("@InvoiceType", DbType.String, this.InvoiceType),
					this.conn.CreateParameter("@Color", DbType.String, this.Color),
					this.conn.CreateParameter("@Size", DbType.String, this.Size),
					this.conn.CreateParameter("@GuiGe", DbType.String, this.GuiGe),
					this.conn.CreateParameter("@CouponItemID", DbType.Int32, this.CouponItemID),
					this.conn.CreateParameter("@PresentExpTotal", DbType.Int32, this.PresentExpTotal),
					this.conn.CreateParameter("@DeliverTypeID", DbType.Int32, this.DeliverTypeID),
					this.conn.CreateParameter("@DeliverCharge", DbType.String, this.DeliverCharge)
				};
				this.conn.BeginTransaction();
				try
				{
					object value = this.conn.ExecuteTransactionScalar(commandText, parameters);
					this.OrderFormID = Convert.ToInt32(value);
					result = this.OrderFormID;
					if (!string.IsNullOrEmpty(text))
					{
						text = text.Substring(0, text.Length - 1);
						if (text.Contains("|"))
						{
							string[] array2 = text.Split(new char[]
							{
								'|'
							});
							for (int i = 0; i < array2.Length; i++)
							{
								string[] oiStrChild = array2[i].Split(new char[]
								{
									','
								});
								IDbDataParameter[] parameters2 = this.OrderItemParameter(oiStrChild);
								this.conn.ExecuteTransaction(commandText2, parameters2);
							}
						}
						else
						{
							string[] oiStrChild2 = text.Split(new char[]
							{
								','
							});
							IDbDataParameter[] parameters2 = this.OrderItemParameter(oiStrChild2);
							this.conn.ExecuteTransaction(commandText2, parameters2);
						}
					}
				}
				catch (Exception ex)
				{
					this.conn.Rollback();
					this.ErrMsg = ex.Message.ToString();
				}
				this.conn.Commit();
			}
			return result;
		}
		private decimal CalculateInvoiceMoney(decimal price, int quantiy, decimal invoiceRate, int needinvoice)
		{
			decimal result = 0m;
			if (needinvoice == 1)
			{
				if (invoiceRate > 0m)
				{
					result = price * quantiy * invoiceRate / 100m;
				}
			}
			return result;
		}
		private void UserUseCoupon(int couponItemID)
		{
			if (couponItemID > 0)
			{
				HKB.Data.Model.CouponItem model = BLLInstance.BllCouponItem.GetModel(couponItemID);
				if (model != null)
				{
					model.CouponItemID = couponItemID;
					model.UseDate = new DateTime?(DateTime.Now);
					model.UseOrderID = new int?(this.OrderFormID);
					model.UseStatus = true;
					BLLInstance.BllCouponItem.Update(model);
				}
			}
		}
		public int EditOrderItemPrice(int orderItemID, decimal editPrice, string explain)
		{
			int result = 0;
			if (orderItemID > 0)
			{
				this.CouponItemID = 0;
				this.MoneyGoods = 0m;
				this.Invoice_TotalPrice = 0m;
				this.Deliver_TotalPrice = 0m;
				this.MoneyTotal = 0m;
				decimal num = 0m;
				decimal d = 0m;
				string text = "";
				Shop_OrderItem shop_OrderItem = new Shop_OrderItem(this.conn);
				DataTable orderItemByID = shop_OrderItem.GetOrderItemByID(orderItemID);
				if (orderItemByID.Rows.Count > 0)
				{
					this.OrderFormID = Convert.ToInt32(orderItemByID.Rows[0]["OrderFormID"].ToString());
					this.OrderFormNum = orderItemByID.Rows[0]["OrderFormNum"].ToString();
					int num2 = Convert.ToInt32(orderItemByID.Rows[0]["Quantity"].ToString());
					int num3 = Convert.ToInt32(orderItemByID.Rows[0]["ProductID"].ToString());
					decimal num4 = Convert.ToDecimal(orderItemByID.Rows[0]["Price"].ToString());
					decimal num5 = editPrice * num2;
					this.MoneyGoods += num5;
					decimal d2 = num4 * num2;
					decimal d3 = 0m;
					decimal d4 = 0m;
					if (orderItemByID.Rows[0]["NeedInvoice"] != DBNull.Value)
					{
						int num6 = Convert.ToInt32(orderItemByID.Rows[0]["NeedInvoice"].ToString());
						if (num6 == 1)
						{
							decimal num7 = Convert.ToDecimal(orderItemByID.Rows[0]["InvoiceRate"].ToString());
							if (num7 > 0m)
							{
								d4 = num5 * num7 / 100m;
								d3 = d2 * num7 / 100m;
							}
						}
					}
					this.Invoice_TotalPrice += d4;
					decimal d5 = 0m;
					Shop_Order shop_Order = new Shop_Order(this.conn);
					DataTable orderInfo = shop_Order.GetOrderInfo(this.OrderFormNum);
					for (int i = 0; i < orderInfo.Rows.Count; i++)
					{
						DataRow dataRow = orderInfo.Rows[i];
						this.CouponItemID = Convert.ToInt32(dataRow["CouponItemID"].ToString());
						if (dataRow["Deliver_TotalPrice"] != DBNull.Value)
						{
							this.Deliver_TotalPrice = Convert.ToDecimal(dataRow["Deliver_TotalPrice"].ToString());
						}
						if (dataRow["DeliverTypeID"] != DBNull.Value)
						{
							int num8 = dataRow["DeliverTypeID"].ToInt32(new int[0]);
							if (num8 > 0)
							{
								if (orderInfo.Columns.Contains("DeliverCharge"))
								{
									if (dataRow["DeliverCharge"] != DBNull.Value)
									{
										decimal d6 = 0m;
										decimal d7 = 0m;
										string text2 = dataRow["DeliverCharge"].ToString();
										string[] contentArray = text2.ToString().Split(new char[]
										{
											'$'
										});
										string deliverChargeContentDetailByName = Shop_DeliverType.GetDeliverChargeContentDetailByName("defaultPrice", contentArray);
										if (!string.IsNullOrEmpty(deliverChargeContentDetailByName))
										{
											d6 = deliverChargeContentDetailByName.ToDecimal2();
										}
										string deliverChargeContentDetailByName2 = Shop_DeliverType.GetDeliverChargeContentDetailByName("deincrementPrice", contentArray);
										if (!string.IsNullOrEmpty(deliverChargeContentDetailByName2))
										{
											d7 = deliverChargeContentDetailByName2.ToDecimal2();
										}
										d5 = d6 + (num2 - 1) * d7;
									}
								}
							}
						}
					}
					num = num5 + d4 + d5;
					d = d2 + d3 + d5;
					DataTable dataTable = this.conn.GetDataTable("Select PUnit From [HLShop_Product] Where ProductID=" + num3);
					string text3 = "";
					if (dataTable.Rows.Count > 0)
					{
						text3 = dataTable.Rows[0]["PUnit"].ToString();
					}
					text = string.Concat(new object[]
					{
						num3,
						",",
						num2,
						",",
						num4,
						",",
						text3
					});
				}
				DataTable byOrderID = shop_OrderItem.GetByOrderID(this.OrderFormID);
				foreach (DataRow dataRow in byOrderID.Rows)
				{
					if (Convert.ToInt32(dataRow["ID"].ToString()) != orderItemID)
					{
						decimal d8 = Convert.ToDecimal(dataRow["Price"].ToString());
						int value = Convert.ToInt32(dataRow["Quantity"].ToString());
						decimal num9 = d8 * value;
						this.MoneyGoods += num9;
						decimal d9 = 0m;
						if (dataRow["NeedInvoice"] != DBNull.Value)
						{
							int num6 = Convert.ToInt32(dataRow["NeedInvoice"].ToString());
							if (num6 == 1)
							{
								decimal num7 = Convert.ToDecimal(dataRow["InvoiceRate"].ToString());
								if (num7 > 0m)
								{
									d9 = num9 * num7 / 100m;
								}
							}
						}
						this.Invoice_TotalPrice += d9;
					}
				}
				decimal couponValue = BLLInstance.BllCouponItem.GetCouponValue(this.CouponItemID);
				this.MoneyTotal = this.MoneyGoods + this.Invoice_TotalPrice + this.Deliver_TotalPrice - couponValue;
				string commandText = string.Concat(new object[]
				{
					"update HLShop_OrderItem set Price=",
					editPrice,
					",totalPrice=",
					num,
					" where ID=",
					orderItemID
				});
				string commandText2 = string.Concat(new object[]
				{
					"update HLShop_Order set MoneyGoods=",
					this.MoneyGoods,
					",Invoice_TotalPrice=",
					this.Invoice_TotalPrice,
					",MoneyTotal=",
					this.MoneyTotal,
					" where OrderFormID=",
					this.OrderFormID
				});
				string commandText3 = "INSERT INTO [HLJXC_StockInfoOrder] (OrderID,InfoNumber,StockOrderType,StockStatus,TotalMoney,CreateDate,Inputer,Remark,OwnerID,StockDate) VALUES (@OrderID,@InfoNumber,@StockOrderType,@StockStatus,@TotalMoney,@CreateDate,@Inputer,@Remark,@OwnerID,@StockDate);select @@IDENTITY";
				string commandText4 = "INSERT INTO [HLJXC_StockItemOrder] (InfoOrderID,InfoNumber,ProductID,StockCount,Unit,Price,OldPrice) VALUES (@InfoOrderID,@InfoNumber,@ProductID,@StockCount,@Unit,@Price,@OldPrice)";
				Random random = new Random();
				string value2 = "GJ" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + random.Next(100, 999);
				decimal num10 = d - num;
				IDbDataParameter[] parameters = new IDbDataParameter[]
				{
					this.conn.CreateParameter("@OrderID", DbType.Int32, this.OrderFormID),
					this.conn.CreateParameter("@InfoNumber", DbType.String, value2),
					this.conn.CreateParameter("@StockOrderType", DbType.String, "xsgjd"),
					this.conn.CreateParameter("@StockStatus", DbType.Int32, -1),
					this.conn.CreateParameter("@TotalMoney", DbType.Decimal, num10),
					this.conn.CreateParameter("@CreateDate", DbType.DateTime, DateTime.Now),
					this.conn.CreateParameter("@Inputer", DbType.String, this.SalerName),
					this.conn.CreateParameter("@Remark", DbType.String, explain),
					this.conn.CreateParameter("@OwnerID", DbType.Int32, this.SalerID),
					this.conn.CreateParameter("@StockDate", DbType.DateTime, DateTime.Now)
				};
				this.conn.BeginTransaction();
				try
				{
					result = this.conn.ExecuteTransaction(commandText2);
					result = this.conn.ExecuteTransaction(commandText);
					object value3 = this.conn.ExecuteTransactionScalar(commandText3, parameters);
					if (!string.IsNullOrEmpty(text))
					{
						string[] array = text.Split(new char[]
						{
							','
						});
						if (array.Length >= 4)
						{
							IDbDataParameter[] parameters2 = new IDbDataParameter[]
							{
								this.conn.CreateParameter("@ProductID", DbType.Int32, Convert.ToInt32(array[0])),
								this.conn.CreateParameter("@StockCount", DbType.Int32, Convert.ToInt32(array[1])),
								this.conn.CreateParameter("@Unit", DbType.String, array[3]),
								this.conn.CreateParameter("@Price", DbType.Decimal, editPrice),
								this.conn.CreateParameter("@OldPrice", DbType.Decimal, Convert.ToDecimal(array[2])),
								this.conn.CreateParameter("@InfoNumber", DbType.String, value2),
								this.conn.CreateParameter("@InfoOrderID", DbType.Int32, Convert.ToInt32(value3))
							};
							result = this.conn.ExecuteTransaction(commandText4, parameters2);
						}
					}
				}
				catch (Exception ex)
				{
					result = 0;
					this.conn.Rollback();
					this.ErrMsg = ex.Message.ToString();
				}
				this.conn.Commit();
			}
			return result;
		}
	}
}
